package org.apache.lucene.ocean.database;

import java.io.Serializable;

import org.apache.lucene.ocean.TransactionSystem;
import org.apache.lucene.ocean.log.LogFile.Record;
import org.apache.lucene.ocean.log.RawLogFile.StreamRecord;

public class GetTransaction implements Task {
  long id;
  
  public Object run(TransactionSystem transactionSystem) throws Exception {
    Record record = transactionSystem.getTransactionLog().getLogFileManager().getRecord(id);
    StreamRecord streamRecord = record.getStreamRecord();
    RecordData recordData = new RecordData();
    recordData.id = id;
    recordData.docBytes = new byte[streamRecord.getDocuments().getLength()];
    streamRecord.getDocuments().getInputStream().read(recordData.docBytes);
    recordData.otherBytes = new byte[streamRecord.getOther().getLength()];
    streamRecord.getOther().getInputStream().read(recordData.otherBytes);
    recordData.docType = record.getRecordHeader().docType;
    recordData.otherType = record.getRecordHeader().otherType;
    return recordData;
  }
  
  public static class RecordData implements Serializable {
    public long id;
    public int docType;
    public byte[] docBytes;
    public int otherType;
    public byte[] otherBytes; 
  }
}
